package com.bosicloud.cmb.ibp.edge.controller;

import com.bosicloud.cmb.ibp.aws.adapter.api.AWSS3Client;
import com.bosicloud.cmb.ibp.commom.dto.UnionResult;
import com.bosicloud.cmb.ibp.edge.constant.UrlDefine;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author Jack Peng / ziliang.peng@bosicloud.com
 */
@Api(value = "上传接口", description = "上传文件")
@RestController
public class UploadController {

    @Autowired
    private AWSS3Client awss3Client;


    @ApiOperation(value = "上传图片", response = UnionResult.class)
    @PostMapping(value = UrlDefine.UPLOAD, consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    @HystrixCommand
    public Object vcode(@RequestPart(value = "file") MultipartFile file) throws IOException {

        return awss3Client.upload(file);

    }





}
